package com.jy.rhin.facade.controller.notification;


import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.infra.NotificationApplicationService;
import com.jy.rhin.infra.repo.notfication.publish.query.PublishMessageQueryHandler;
import com.jy.rhin.sdk.dto.notification.req.IdDto;
import com.jy.rhin.sdk.dto.notification.req.PublishMessagePageReqDto;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessageDetailDto;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessageDto;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessagePageDto;
import com.jy.rhin.support.notification.convertor.DefaultConverter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author dhl
 * @date 2022/7/1
 * @Description
 */
@RestController
@RequestMapping("/notification/publishMessage")
@Api(tags = "事件总线api", value = "通知记录管理api")
@Slf4j
public class PublishMessageBizController {

    @Resource
    private PublishMessageQueryHandler publishMessageQueryHandler;
    @Resource
    DefaultConverter defaultConverter;
    @Resource
    private NotificationApplicationService notificationApplicationService;
    @ApiOperation("通知记录管理api-通知消息分页查询")
    @GetMapping("/queryPublishMessagePage")
    public Result<Page<PublishMessagePageDto>> queryPublishMessagePage(PublishMessagePageReqDto req) {
        return Result.success(publishMessageQueryHandler.queryPublishMessagePage(req));
    }

    @ApiOperation("通知记录管理api-通知消息详情查询")
    @GetMapping("/queryPublishMessageDetail")
    public Result<PublishMessageDetailDto> queryPublishMessageDetail(IdDto req) {
    	PublishMessageDetailDto result = notificationApplicationService.queryPublishMessageDetail(req);
    	if(result.getTopicExp().contains("rhin")){
    		PublishMessageDto message = new PublishMessageDto();
    		message.setTopicExp(result.getTopicExp());
    		message.setMessage(result.getContent());
            result.setContent(defaultConverter.buildMessageContent(message));
    	}
    	
        return Result.success(result);
    }
}
